package com.baizhi.service.impl;

import com.baizhi.dao.BannerDAO;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class BannerServiceImpl implements BannerService {

    @Autowired
    private BannerDAO bannerDAO;

    @Override
    public PageInfo<Banner> showAll(int page,int limit) {
        PageHelper.startPage(page, limit);
        List<Banner> banners = bannerDAO.selectAll();
        PageInfo<Banner> pageInfo = new PageInfo<>(banners);
        return  pageInfo;
    }

    @Override
    public void add(Banner banner) {
        bannerDAO.insertBanner(banner);
    }

    @Override
    public void remove(int id) {
        bannerDAO.deleteById(id);
    }

    @Override
    public void update(Banner banner) {
        bannerDAO.updateBanner(banner);
    }

    @Override
    public void updateState(int id) {
        bannerDAO.updateState(id);
    }

    @Override
    public Banner showById(int id) {
        return bannerDAO.selectById(id);
    }
}
